package day2;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentManager {

	public static void main(String[] args) {
		// 通过Scanner可以从控制台读取用户输入的数据
		Scanner scanner = new Scanner(System.in);
		Student[] array = new Student[4];
		ArrayList<Student> list = new ArrayList<Student>();
		
		while (true) {
			// Unreachable code
			System.out.println("请输入id：");
			int id = scanner.nextInt();
			System.out.println("请输入名字:");
			String name = scanner.next();
			System.out.println("请输入年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入性别:");
			String gender = scanner.next();
			Student student = new Student(id, name, age, gender);
			list.add(student);
			
			System.out.println("您是否要退出： -1退出, 0继续");
			int quit = scanner.nextInt();
			if (quit == -1) {
				break;
			}
		}
		
		for (Student student : list) {
			System.out.println(student);
		}
		
		while (true) {
			System.out.println("-------------------------");
			System.out.println("根据id搜索输入1");
			System.out.println("根据name搜索输入2");
			System.out.println("根据age搜索输入3");
			System.out.println("根据gender搜索输入4");
			System.out.println("您是否要退出： -1退出, 0继续");
			System.out.println("-------------------------");
			int type = scanner.nextInt();
			// 对于一些退出操作、或者非法的情况，直接写在最前边
			if (type == -1) {
				System.out.println("退出程序");
				break;
			}
			
			switch (type) {
			case -1:
				break;
			case 1:// 根据id搜索
				
				break;
			case 2:// 根据name搜索
				System.out.println("请输入要搜索的名字：");
				String name = scanner.next();
				boolean isSearchByNameFound = false;//  根据根据名字没有找到
				for (Student student : list) {
					// 在java里面判断字符串的内容是不是相等使用equal的方法
					if (name.equals(student.getName())) {
						System.out.println(student);
						isSearchByNameFound = true;
					}
				}
				if (isSearchByNameFound == false) {
					System.out.println("没有该姓名的学生");
				}
				break;
			case 3:// 根据年龄搜索
				System.out.println("请输入要搜索的年龄：");
				int age = scanner.nextInt();
				for (Student student : list) {
					if (age == student.getAge()) {
						System.out.println(student);
					}
				}
				break;
			case 4:
				break;

			default:
				break;
			}
		}
		
		
		
	}
}
